//
//  BaseViewController.swift
//  SinaWeiBo
//
//  Created by ZKJ on 2017/8/28.
//  Copyright © 2017年 ZKJ. All rights reserved.
//

import UIKit

class BaseViewController: UITableViewController {

    // MARK:- 懒加载属性
    lazy var visitorView : VisitorView = VisitorView.visitorView()
    
    // MARK:- 定义变量
    var isLogin : Bool = UserInfoViewModel.sharInstance.isLogin
    
    // MARK:- 系统回调函数
    override func loadView() {
        
        // 判断要加载哪一个View
        isLogin ? super.loadView() : setUpVisitorView()
    }
    
    // MARK:- 系统回调函数
    override func viewDidLoad() {
        super.viewDidLoad()

        setUpNavigationItem()
    }
}

// MARK:- 设置UI界面
extension BaseViewController {
    // MARK:- 设置访客视图
    fileprivate func setUpVisitorView() {
        view = visitorView
        visitorView.registerBtn.addTarget(self, action: #selector(BaseViewController.registerBtnClick), for: .touchUpInside)
        visitorView.loginBtn.addTarget(self, action: #selector(BaseViewController.loginBtnClick), for: .touchUpInside)
    }
    
    // MARK:- 设置导航条左右按钮
    fileprivate func setUpNavigationItem() {
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .plain, target: self, action: #selector(BaseViewController.registerBtnClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .plain, target: self, action: #selector(BaseViewController.loginBtnClick))
    }
}

// MARK:- 监听事件
extension BaseViewController {
    @objc fileprivate func registerBtnClick() {
        print("注册")
    }
    @objc fileprivate func loginBtnClick() {
        let oauthVC = OauthViewController()
        let nav = UINavigationController(rootViewController: oauthVC)
        present(nav, animated: true, completion: nil)
    }
}


